#Jaroslav Crhonek (crhonjar@fit.cvut.cz)

def count(file)
  stat = {}
  File.open(file,"r") do |f|
    f.readlines.each do |line|
      line = line.downcase
      line = line.gsub(/[.,"'!$%^&*()?:;]/,'')
      line.split(" ").each do |word|
        if stat.include?(word)
          stat[word] = stat[word]+1
        else
          stat[word] = 1
        end
      end
    end
  end
  stat
end

puts ">> Start"
a=count("cviko2_3.txt")
a = a.sort {|a,b| b[1]<=>a[1]}
a.each {|pair| print "#{pair[0]}:\t#{pair[1]}\n"}
puts "<< Stop"